#!/usr/bin/env bash

#-----------------------------------------------------------------------------------------------------
# Nodejs 下载地址
#   镜像1: https://nodejs.org/dist/ (https://nodejs.org/dist/v16.18.0/node-v16.18.0-linux-x64.tar.gz)
# OracleJDK 下载地址
#   镜像1: https://www.injdk.cn/ (https://d6.injdk.cn/oraclejdk/11/jdk-11.0.16.1_linux-x64_bin.tar.gz) (https://d6.injdk.cn/oraclejdk/8/jdk-8u341-linux-x64.tar.gz)
#   镜像2: http://www.codebaoku.com/jdk/jdk-index.html (https://114-233-56-217.d.cjjd09.com:30443/123-511/85b2a0b8/1661483-0/85b2a0b8c16863b3ad55e742ac2ba9ff?v=3&t=1667188559&s=f2df45083bb69864446f801bf25b725c&i=dde8a980&filename=jdk-11.0.15.1_linux-x64_bin.tar.gz&d=6ee52da1)
#-----------------------------------------------------------------------------------------------------

# 配置
BASE_DIR="/opt/jenkins-agent"

# 软件
#--- 运行jenkins-agent的jre
JENKINS_JAVA_URL="https://d6.injdk.cn/oraclejdk/21/jdk-21_linux-x64_bin.tar.gz"
#--- jdk (8 | 11 | 17 | 21)
JDK_URL=(
  "https://d6.injdk.cn/oraclejdk/8/jdk-8u381-linux-x64.tar.gz"
  "https://d6.injdk.cn/oraclejdk/11/jdk-11.0.21_linux-x64_bin.tar.gz"
  "https://d6.injdk.cn/oraclejdk/17/jdk-17_linux-x64_bin.tar.gz"
  "https://d6.injdk.cn/oraclejdk/21/jdk-21_linux-x64_bin.tar.gz"
)
#--- gradle (6.8.3 | 6.9.4 | 7.6.3 | 8.2.1)
GRADLE_URL=(
  "https://services.gradle.org/distributions/gradle-6.8.3-bin.zip"
  "https://services.gradle.org/distributions/gradle-6.9.4-bin.zip"
  "https://services.gradle.org/distributions/gradle-7.6.3-bin.zip"
  "https://services.gradle.org/distributions/gradle-8.2.1-bin.zip"
)
#--- maven (3.8.8 | 3.9.6)
MAVEN_URL=(
  "https://dlcdn.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz"
  "https://dlcdn.apache.org/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz"
)
#--- nodejs (16 | 18 | 20)
NODEJS_URL=(
  "https://nodejs.org/dist/v16.20.2/node-v16.20.2-linux-x64.tar.gz"
  "https://nodejs.org/dist/v18.19.0/node-v18.19.0-linux-x64.tar.gz"
  "https://nodejs.org/dist/v20.10.0/node-v20.10.0-linux-x64.tar.gz"
)

# 安装标识
#--- SSH用户
SSH_OPTIONS="-o ConnectTimeout=600 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
SSH_USER=""
SSH_PASSWORD=""
SSH_PRIVATE_KEY=""
SSH_PORT=""
#--- SUDO用户
SUDO_TAG="0"
SUDO_USER=""
SUDO_PASSWORD=""
#--- 指令
INIT_TAG="0"
#--- 指令参数
JENKINS_AGENT=""
JENKINS_AGENT_JNLP_URL=""
JENKINS_AGENT_SECRET=""
GIT_TAG="1"
JAVA_TAG="0"
GRADLE_TAG="0"
MAVEN_TAG="0"
NODEJS_TAG="0"

# 脚本设置
TMP_DIR="$(rm -rf /tmp/jenkins-agent-install* && mktemp -d -t jenkins-agent-install.XXXXXXXXXX)"
LOG_FILE="${TMP_DIR}/jenkins-agent-install.log"
ERROR_INFO="\n\033[31mERROR Summary: \033[0m\n  "
ACCESS_INFO="\n\033[32mACCESS Summary: \033[0m\n  "
SCRIPT_PARAMETER="$*"
COMMAND_OUTPUT=""

######################################################################################################
# 通用函数
######################################################################################################
# 信号处理
function trap::info() {
  [[ ${#ERROR_INFO} -gt 37 ]] && echo -e "$ERROR_INFO"
  [[ ${#ACCESS_INFO} -gt 38 ]] && echo -e "$ACCESS_INFO"
  [ -f "$LOG_FILE" ] && echo -e "\n\n  See detailed log >>> cat $LOG_FILE \n\n"
  trap '' EXIT
  exit
}

# 错误日志
function log::error() {
  local item; item="[$(date +'%Y-%m-%dT%H:%M:%S.%N%z')]: \033[31mERROR:   \033[0m$*"
  ERROR_INFO="${ERROR_INFO}${item}\n  "
  echo -e "${item}" | tee -a "$LOG_FILE"
}

# 基础日志
function log::info() {
  printf "[%s]: \033[32mINFO:    \033[0m%s\n" "$(date +'%Y-%m-%dT%H:%M:%S.%N%z')" "$*" | tee -a "$LOG_FILE"
}

# 警告日志
function log::warning() {
  printf "[%s]: \033[33mWARNING: \033[0m%s\n" "$(date +'%Y-%m-%dT%H:%M:%S.%N%z')" "$*" | tee -a "$LOG_FILE"
}

# 访问信息
function log::access() {
  ACCESS_INFO="${ACCESS_INFO}$*\n  "
  printf "[%s]: \033[32mINFO:    \033[0m%s\n" "$(date +'%Y-%m-%dT%H:%M:%S.%N%z')" "$*" | tee -a "$LOG_FILE"
}

# 执行日志
function log::exec() {
  printf "[%s]: \033[34mEXEC:    \033[0m%s\n" "$(date +'%Y-%m-%dT%H:%M:%S.%N%z')" "$*" >> "$LOG_FILE"
}

# 检查返回码
function check::exit_code() {
  local code=${1:-}
  local app=${2:-}
  local desc=${3:-}
  local exit_script=${4:-}
  if [[ "${code}" == "0" ]]; then
    log::info "[${app}]" "${desc} succeeded."
  else
    log::error "[${app}]" "${desc} failed."
    [[ "$exit_script" == "exit" ]] && exit "$code"
  fi
}

# 重试
function utils::retry() {
  local retries=$1
  shift
  local count=0
  until eval "$*"; do
    exit=$?
    wait=$((2 ** count))
    count=$((count + 1))
    if [ "$count" -lt "$retries" ]; then
      echo "Retry $count/$retries exited $exit, retrying in $wait seconds..."
      sleep $wait
    else
      echo "Retry $count/$retries exited $exit, no more retries left."
      return $exit
    fi
  done
  return 0
}

# 转义引号
function utils::quote() {
  # shellcheck disable=SC2046
  if [ $(echo "$*" | tr -d "\n" | wc -c) -eq 0 ]; then
    echo "''"
  elif [ $(echo "$*" | tr -d "[a-z][A-Z][0-9]:,.=~_/\n-" | wc -c) -gt 0 ]; then
    printf "%s" "$*" | sed -e "1h;2,\$H;\$!d;g" -e "s/'/\'\"\'\"\'/g" | sed -e "1h;2,\$H;\$!d;g" -e "s/^/'/g" -e "s/$/'/g"
  else
    echo "$*"
  fi
}

# 检查命令是否存在
function check::command_exists() {
  local cmd=${1}
  local package=${2}
  if command -V "$cmd" > /dev/null 2>&1; then
    log::info "[check]" "$cmd command exists."
  else
    log::warning "[check]" "I require $cmd but it's not installed."
    log::warning "[check]" "install $package package."
    command::exec "127.0.0.1" "yum install -y ${package}"
    check::exit_code "$?" "check" "$package install" "exit"
  fi
}

# 执行命令
function command::exec() {
  local host=${1:-"127.0.0.1"}
  shift
  local command="$*"
  if [[ "${SUDO_TAG:-}" == "1" ]]; then
    sudo_options="sudo -H -n -u ${SUDO_USER}"
    if [[ "${SUDO_PASSWORD:-}" != "" ]]; then
       sudo_options="${sudo_options// -n/} -p \"\" -S <<< \"${SUDO_PASSWORD}\""
    fi
    command="$sudo_options bash -c $(utils::quote "$command")"
  fi
  command="$(utils::quote "$command")"
  if [[ "${host}" == "127.0.0.1" ]]; then
    # 本地执行
    log::exec "[command]" "bash -c $(printf "%s" "${command//${SUDO_PASSWORD:-}/zzzzzz}")"
    # shellcheck disable=SC2094
    COMMAND_OUTPUT=$(eval bash -c "${command}" 2>> "$LOG_FILE" | tee -a "$LOG_FILE")
    local status=$?
  else
    # 远程执行
    local ssh_cmd="ssh"
    if [[ "${SSH_PASSWORD}" != "" ]]; then
      ssh_cmd="sshpass -p \"${SSH_PASSWORD}\" ${ssh_cmd}"
    elif [[ "$SSH_PRIVATE_KEY" != "" ]]; then
      [ -f "${SSH_PRIVATE_KEY}" ] || { log::error "[exec]" "ssh private_key:${SSH_PRIVATE_KEY} not found."; exit 1; }
      ssh_cmd="${ssh_cmd} -i $SSH_PRIVATE_KEY"
    fi
    log::exec "[command]" "${ssh_cmd//${SSH_PASSWORD:-}/zzzzzz} ${SSH_OPTIONS} ${SSH_USER}@${host} -p ${SSH_PORT} bash -c $(printf "%s" "${command//${SUDO_PASSWORD:-}/zzzzzz}")"
    # shellcheck disable=SC2094
    COMMAND_OUTPUT=$(eval "${ssh_cmd} ${SSH_OPTIONS} ${SSH_USER}@${host} -p ${SSH_PORT}" bash -c '"${command}"' 2>> "$LOG_FILE" | tee -a "$LOG_FILE")
    local status=$?
  fi
  return $status
}

######################################################################################################
# 安装函数
######################################################################################################
# 检查用到的命令
function check::command() {
  check::command_exists ssh openssh-clients
  check::command_exists tar tar
  check::command_exists wget wget
  check::command_exists unzip unzip
}

# 创建文件夹
function init:mkdir() {
  log::info "[mkdir]" "创建目录..."
  local host="127.0.0.1"
  command::exec "${host}" "
    sudo mkdir -p ${BASE_DIR}
    sudo chown -R \$(id -u):\$(id -g) ${BASE_DIR}
  "
  check::exit_code "$?" "mkdir" "$host 创建目录:${BASE_DIR}" "exit"
  log::info "[mkdir]" "创建目录成功!"
}

# 下载
function init:jenkins_agent() {
  log::info "[jenkins-agent]" "下载jenkins-agent..."
  local host="127.0.0.1"
  local tmp_download="tmp_download"
  local tmp_dir="tmp"
  local java_path="${BASE_DIR}/jenkins/install_jenkins_agent_jre.txt"
  local agent_path="${BASE_DIR}/install_jenkins_agent.txt"
  local java_mem_opts='-server -Xmx1g'
  local database_opts=' -Ddatabase.codeset=ISO-8859-1 -Ddatabase.logging=false'
  local java_opts_ext=' -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Dapplication.codeset=UTF-8 -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Shanghai'
  command::exec "${host}" "
    mkdir -p ${BASE_DIR}/workspace
    java_bin=\"\"
    agent_file=\"\"
    # 安装JRE
    if [ ! -f "$java_path" ]; then
      mkdir -p ${BASE_DIR}/jenkins-agent-jre
      cd ${BASE_DIR}/jenkins-agent-jre
      rm -rf ./${tmp_download}
      mkdir ./${tmp_download}
      cd ./${tmp_download}
      wget --timeout=10 --waitretry=3 --tries=5 --retry-connrefused --no-check-certificate ${JENKINS_JAVA_URL}
      file_name=\`ls ./ | head -n 1\`
      if [ -z \$file_name ];then
        echo '下载失败=${JENKINS_JAVA_URL}'
        cd ../
      else
        mkdir ./${tmp_dir}
        tar -zxvf \$file_name -C ./${tmp_dir}
        mv \$file_name ../\$file_name
        cd ./${tmp_dir}
        file_name=\`ls ./ | head -n 1\`
        mv \$file_name ../../\$file_name
        cd ../../
        echo \"\$file_name\" >> ${java_path}
        java_bin=\"${BASE_DIR}/jenkins-agent-jre/\$file_name/bin/java\"
        \$file_name/bin/java -version
      fi
      rm -rf ./${tmp_download}
    fi
    # 安装 jenkins-agent
    if [ ! -f "$agent_path" ]; then
      cd ${BASE_DIR}
      rm -rf ./${tmp_download}
      mkdir ./${tmp_download}
      cd ./${tmp_download}
      wget --timeout=10 --no-check-certificate ${JENKINS_AGENT}
      file_name=\`ls ./ | head -n 1\`
      if [ -z \$file_name ];then
        echo '下载失败=${JENKINS_AGENT}'
      else
        mv \$file_name ../\$file_name
        echo \"\$file_name\" >> ${agent_path}
        agent_file=\"${BASE_DIR}/\$file_name\"
      fi
      cd ../
      rm -rf ./${tmp_download}
    fi
    # 生成脚本
    if [[ -n \$java_bin && -n \$agent_file ]]; then
      # 写文件start.sh文件
      cat << EOF > ${BASE_DIR}/start.sh
#!/bin/bash

jnlpUrl='${JENKINS_AGENT_JNLP_URL}'
secret='${JENKINS_AGENT_SECRET}'
workDir='${BASE_DIR}/workspace'

#-------------------------------------------------------------------
java='\$java_bin'
agent_file='\$agent_file'
java_mem_opts=' -DappName=jenkins-agent $java_mem_opts'
database_opts='$database_opts'
java_opts_ext='$java_opts_ext'
#-------------------------------------------------------------------

pid=\\\`ps -ef | grep 'DappName=jenkins-agent ' | grep -v 'grep' | awk '{print \\\$2}'\\\`
if [ -z \\\$pid ];then
  nohup \\\$java \\\$java_mem_opts \\\$database_opts \\\$java_opts_ext -jar \\\$agent_file -jnlpUrl \\\$jnlpUrl -secret \\\$secret -workDir \\\$workDir >${BASE_DIR}/agent-logs.log 2>&1 &
  echo 'jenkins-agent启动成功!'
else
  echo 'jenkins-agent正在运行...'
fi
echo '查看日志:  tail -F ${BASE_DIR}/agent-logs.log -n 100'
EOF
      # 写文件kill.sh文件
      cat << EOF > ${BASE_DIR}/kill.sh
#!/bin/bash

pid=\\\`ps -ef | grep 'DappName=jenkins-agent ' | grep -v 'grep' | awk '{print \\\$2}'\\\`
if [ -z \\\$pid ];then
  echo 'jenkins-agent未运行'
else
  ps -ef | grep 'DappName=jenkins-agent ' | grep -v 'grep' | awk '{print \\\$2}' | xargs kill
  echo 'jenkins-agent已停止!'
fi
EOF
      chmod +x ${BASE_DIR}/start.sh
      chmod +x ${BASE_DIR}/kill.sh
      sudo chown -R \$(id -u):\$(id -g) ${BASE_DIR}
    fi
  "
  check::exit_code "$?" "jenkins-agent" "$host 下载jenkins-agent" "exit"
  log::info "[jenkins-agent]" "jenkins-agent下载成功!"
}

# 安装git
function init:git() {
  log::info "[git]" "安装git..."
  local host="127.0.0.1"
  command::exec "${host}" "
    sudo yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm
    sudo yum -y install git
    git --version
    git config --global credential.helper store
  "
  check::exit_code "$?" "git" "$host 安装git" "exit"
  log::info "[git]" "git安装成功!"
}

# 安装java
function init:java() {
  log::info "[java]" "安装java..."
  local host="127.0.0.1"
  local tmp_download="tmp_download"
  local tmp_dir="tmp"
  local java_path="${BASE_DIR}/env/java/install_java.txt"
  for url in "${JDK_URL[@]}"
  do
    command::exec "${host}" "
      if [ ! -f "$java_path" ] || ! grep -q "$url" "$java_path"; then
        mkdir -p ${BASE_DIR}/env/java
        cd ${BASE_DIR}/env/java
        rm -rf ./${tmp_download}
        mkdir ./${tmp_download}
        cd ./${tmp_download}
        wget --timeout=10 --waitretry=3 --tries=5 --retry-connrefused --no-check-certificate ${url}
        file_name=\`ls ./ | head -n 1\`
        if [ -z \$file_name ];then
          echo '下载失败=${url}'
          cd ../
        else
          mkdir ./${tmp_dir}
          tar -zxvf \$file_name -C ./${tmp_dir}
          mv \$file_name ../\$file_name
          cd ./${tmp_dir}
          file_name=\`ls ./ | head -n 1\`
          mv \$file_name ../../\$file_name
          cd ../../
          echo "${url}" >> ${java_path}
        fi
        rm -rf ./${tmp_download}
      fi
    "
    check::exit_code "$?" "java" "$host 安装java: $url" "exit"
  done
  log::info "[java]" "java安装成功!"
}

# 安装gradle
function init:gradle() {
  log::info "[gradle]" "安装gradle..."
  local host="127.0.0.1"
  local tmp_download="tmp_download"
  local tmp_dir="tmp"
  local gradle_path="${BASE_DIR}/env/gradle/install_gradle.txt"
  for url in "${GRADLE_URL[@]}"
  do
    command::exec "${host}" "
      if [ ! -f "$gradle_path" ] || ! grep -q "$url" "$gradle_path"; then
        mkdir -p ${BASE_DIR}/env/gradle
        cd ${BASE_DIR}/env/gradle
        rm -rf ./${tmp_download}
        mkdir ./${tmp_download}
        cd ./${tmp_download}
        wget --timeout=10 --waitretry=3 --tries=5 --retry-connrefused --no-check-certificate ${url}
        file_name=\`ls ./ | head -n 1\`
        if [ -z \$file_name ];then
          echo '下载失败=${url}'
          cd ../
        else
          mkdir ./${tmp_dir}
          unzip \$file_name -d ./${tmp_dir}
          mv \$file_name ../\$file_name
          cd ./${tmp_dir}
          file_name=\`ls ./ | head -n 1\`
          mv \$file_name ../../\$file_name
          cd ../../
          echo "${url}" >> ${gradle_path}
        fi
        rm -rf ./${tmp_download}
      fi
    "
    check::exit_code "$?" "gradle" "$host 安装gradle: $url" "exit"
  done
  log::info "[gradle]" "gradle安装成功!"
}

# 安装maven
function init:maven() {
  log::info "[maven]" "安装maven..."
  local host="127.0.0.1"
  local tmp_download="tmp_download"
  local tmp_dir="tmp"
  local maven_path="${BASE_DIR}/env/maven/install_maven.txt"
  for url in "${MAVEN_URL[@]}"
  do
    command::exec "${host}" "
      if [ ! -f "$maven_path" ] || ! grep -q "$url" "$maven_path"; then
        mkdir -p ${BASE_DIR}/env/maven
        cd ${BASE_DIR}/env/maven
        rm -rf ./${tmp_download}
        mkdir ./${tmp_download}
        cd ./${tmp_download}
        wget --timeout=10 --waitretry=3 --tries=5 --retry-connrefused --no-check-certificate ${url}
        file_name=\`ls ./ | head -n 1\`
        if [ -z \$file_name ];then
          echo '下载失败=${url}'
          cd ../
        else
          mkdir ./${tmp_dir}
          tar -zxvf \$file_name -C ./${tmp_dir}
          mv \$file_name ../\$file_name
          cd ./${tmp_dir}
          file_name=\`ls ./ | head -n 1\`
          mv \$file_name ../../\$file_name
          cd ../../
          echo "${url}" >> ${maven_path}
        fi
        rm -rf ./${tmp_download}
      fi
    "
    check::exit_code "$?" "maven" "$host 安装maven: $url" "exit"
  done
  log::info "[maven]" "maven安装成功!"
}

# 安装nodejs
function init:nodejs() {
  log::info "[nodejs]" "安装nodejs..."
  local host="127.0.0.1"
  local tmp_download="tmp_download"
  local tmp_dir="tmp"
  local nodejs_path="${BASE_DIR}/env/nodejs/install_nodejs.txt"
  for url in "${NODEJS_URL[@]}"
  do
    command::exec "${host}" "
      if [ ! -f "$nodejs_path" ] || ! grep -q "$url" "$nodejs_path"; then
        mkdir -p ${BASE_DIR}/env/nodejs
        cd ${BASE_DIR}/env/nodejs
        rm -rf ./${tmp_download}
        mkdir ./${tmp_download}
        cd ./${tmp_download}
        wget --timeout=10 --waitretry=3 --tries=5 --retry-connrefused --no-check-certificate ${url}
        file_name=\`ls ./ | head -n 1\`
        if [ -z \$file_name ];then
          echo '下载失败=${url}'
          cd ../
        else
          mkdir ./${tmp_dir}
          tar -zxvf \$file_name -C ./${tmp_dir}
          mv \$file_name ../\$file_name
          cd ./${tmp_dir}
          file_name=\`ls ./ | head -n 1\`
          mv \$file_name ../../\$file_name
          cd ../../
          echo "${url}" >> ${nodejs_path}
        fi
        rm -rf ./${tmp_download}
      fi
    "
    check::exit_code "$?" "nodejs" "$host 安装nodejs: $url" "exit"
  done
  log::info "[nodejs]" "安装nodejs成功!"
}

######################################################################################################
# 主调用逻辑
######################################################################################################
trap trap::info 1 2 3 15 EXIT

# 使用帮助
function help::usage() {
  cat << EOF
Usage:
  jenkins-agent-install-centos.sh [command]

Available Commands:
  init                初始化系统
Flag:
  -base-dir           新增用户名, 默认: '/data/jenkins-agent'
  -agent              jenkins-agent下载地址(\${JENKINS_URL}/jnlpJars/agent.jar)， 默认: ''
  -jnlpUrl            jenkins-agent的jnlpUrl参数(\${JENKINS_URL}/computer/\${AGENT_NAME}/jenkins-agent.jnlp)， 默认: ''
  -secret             jenkins-agent的secret参数， 默认: ''
  -git                是否安装git
  -java               是否安装java
  -gradle             是否安装gradle
  -maven              是否安装maven
  -nodejs             是否安装nodejs

Example:
  jenkins-agent-install-centos.sh init \\
    -base-dir '/data/jenkins-agent' \\
    -agent '' \\
    -jnlpUrl '' \\
    -secret '' \\
    -git 0 \\
    -java 0 \\
    -gradle 0 \\
    -maven 0 \\
    -nodejs 0

EOF
  exit 1
}

# 参数处理
[ "$#" == "0" ] && help::usage
while [ "${1:-}" != "" ]; do
  case $1 in
    # -------------------------------------------------------------- 指令
    init  )                 INIT_TAG="1"
                            ;;
    # -------------------------------------------------------------- 指令参数
    -base-dir )             shift
                            BASE_DIR=${1:-BASE_DIR}
                            ;;
    -agent )                shift
                            JENKINS_AGENT=${1:-JENKINS_AGENT}
                            ;;
    -jnlpUrl )              shift
                            JENKINS_AGENT_JNLP_URL=${1:-JENKINS_AGENT_JNLP_URL}
                            ;;
    -secret )               shift
                            JENKINS_AGENT_SECRET=${1:-JENKINS_AGENT_SECRET}
                            ;;
    -git )                  shift
                            GIT_TAG=${1:-GIT_TAG}
                            ;;
    -java )                 shift
                            JAVA_TAG=${1:-JAVA_TAG}
                            ;;
    -gradle )               shift
                            GRADLE_TAG=${1:-GRADLE_TAG}
                            ;;
    -maven )                shift
                            MAVEN_TAG=${1:-MAVEN_TAG}
                            ;;
    -nodejs )               shift
                            NODEJS_TAG=${1:-NODEJS_TAG}
                            ;;
    * )                     help::usage
                            exit 1
  esac
  shift
done

# 开始
log::info "[start]" "bash $0 ${SCRIPT_PARAMETER}"
# 动作
if [[ "${INIT_TAG:-}" == "1" ]]; then
  check::command
  init:mkdir
  [[ -n "${JENKINS_AGENT:-}" ]] && { init:jenkins_agent; }
  [[ "${GIT_TAG:-}" == "1" ]] && { init:git; }
  [[ "${JAVA_TAG:-}" == "1" ]] && { init:java; }
  [[ "${GRADLE_TAG:-}" == "1" ]] && { init:gradle; }
  [[ "${MAVEN_TAG:-}" == "1" ]] && { init:maven; }
  [[ "${NODEJS_TAG:-}" == "1" ]] && { init:nodejs; }
else
  help::usage
fi

# bash <(curl -s https://gitee.com/LiZhiW/helm-chart/raw/master/01shell/jenkins-agent-install-centos.sh) [cmd]
